
module MatrixHelpers

module APP
	def nl2br(s)
		s.to_s.gsub(/\r\n|\r|\n/, "<br />\n")
	end

	alias :h :nl2br
end

module DM
	include DataMapper::Inflector

	def link
		"/#{underscore self.class.name}/#{self.id}"
	end

	def link_tag(text=nil, options={})
		text = self.name if text.nil?
		properties = ""
		options.each do |k,v|
			properties += "#{k}=\"#{v}\" "
		end
		"<a href=\"#{self.link}\" #{properties}>#{text}</a>"
	end

	def edit_tag(text=nil, options={})
		text = self.name if text.nil?
		properties = ""
		options.each do |k,v|
			properties += "#{k}=\"#{v}\" "
		end
		"<a href=\"#{self.link}/edit\" #{properties}>#{text}</a>"
	end
end
end
